#include <iostream>
#include <vector>
#include <queue>
#include <memory.h>

#define MAXN 30005
using namespace std;

vector<int> G[MAXN];
int vis[MAXN], n, m;
vector<int> ans;

void TopSort() {
	priority_queue<int> q;
	for (int i = 1; i <= n; ++i){
		if (vis[i] == 0) q.push(i);
	}

	while(!q.empty()){
		int u = q.top();
		ans.push_back(u);
		q.pop();
		for (unsigned i = 0; i < G[u].size(); ++i){
			int v = G[u][i];
			--vis[v];
			if (vis[v] == 0){
				q.push(v);
			}
		}
	}	
}

int main() {
	int T;
	cin >> T;

	while (T--) {
		int x, y;
		cin >> n >> m;

		ans.clear();
		memset(vis, 0, sizeof(vis));
		for (int i = 0; i <= n; ++i) {
			G[i].clear();
		}

		for(int i = 1; i <= m; ++i){
			cin >> x >> y;
			G[y].push_back(x);
			++vis[x];
		}

		TopSort();

		for (int i = ans.size() - 1; i >= 0; --i) {
			cout << ans[i] << " ";
		}
		cout << endl;
	}
	

	return 0;
}
